<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>话题编辑</title>

  {include file='common/_require'/}
</head>

<body>

  {include file='common/_header'/}

  <div class="layui-container fly-marginTop fly-user-main">
    {include file='common/_user'/}
    <script>$('.user-nav-item-topic-status').addClass('layui-this')</script>


    <div class="fly-panel fly-panel-user" pad20>

      <fieldset class="layui-elem-field layui-field-title">
        <legend>话题编辑</legend>
        <div class="layui-field-box">
          <form class="layui-form" action="" lay-filter="*">
            <input type="hidden" name="id" value="{$topic.id}">
            <div class="layui-form-item">
              <label class="layui-form-label">标题</label>
              <div class="layui-input-block">
                <input type="text" name="title" required lay-verify="required" value="{$topic.title}" placeholder="请输入标题" autocomplete="off" class="layui-input">
              </div>
            </div>
            
            <div class="layui-form-item layui-form-text">
              <label class="layui-form-label">简介</label>
              <div class="layui-input-block">
                <textarea name="desc" placeholder="请输入简介" class="layui-textarea">{$topic.desc}</textarea>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">状态</label>
              <div class="layui-input-block">
                <input type="radio" name="status" value="0" title="在线">
                <input type="radio" name="status" value="1" title="下架">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">排序 <span class="layui-word-aux">越大越靠前</span> </label>
              <div class="layui-input-block">
                <input type="text" name="sort" value="{$topic.sort}" required lay-verify="required" placeholder="请输入排序" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">类型</label>
              <div class="layui-input-block">
                <select name="type" lay-verify="">
                  <option value="normal">默认类型</option>
                  {volist name='\app\model\Nav::getListIndexNav("topic_type")' id='topic_type'}
                  <option value="{$topic_type.key}">{$topic_type.title}</option>
                  {/volist}
                </select>     
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="update">立即提交</button>
                
              </div>
            </div>
          </form>
        </div>
      </fieldset>
    </div>
  </div>
  </div>
  {include file='common/_footer'/}

  <script>

    layui.use(['form', 'upload'], function () {
      var form = layui.form
      form.val('*',{
        status:'{$topic.status}',
        type:'{$topic.type}',
      })

      form.on('submit(update)',function(data){

        $.post('{:url("update")}',data.field,function(result){
          if(result.code == 0){
            layer.msg('修改成功')
            setTimeout(() => {
              location.href = '{:url("Topic/statusManage",["page"=>$Request.param.page])}'
            }, 1200);
          }else{
            layer.msg(result.msg)
          }
        })

        return false;
      })

    })

  </script>
</body>

</html>